﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Fysh.ComputerScience.Genetics
{
    public class LikelihoodEvaluator
    {
        private List<Node> _interiorNodes;
        private string _bases = "GATC";
        private PhylogeneticTree _currentTree;
        /// <summary>
        /// Evaluates the maximum likelihood of a given tree
        /// </summary>
        /// <param name="executionMode">Execution mode of method</param>
        public double Evaluate(PhylogeneticTree tree, EvolutionaryDnaModel dnaModel, double[] dnaModelParameterArray, ExecutionMode executionMode)
        {
            throw new System.NotImplementedException();
            //identify all interior nodes in the tree
            ExploreNode(tree.RootNode);
        }

        /// <summary>
        /// Asynchronous implementation of the evaluate method
        /// </summary>
        /// <param name="executionMode">Execution mode of operation</param>
        public IAsyncResult BeginEvaluation(PhylogeneticTree tree, EvolutionaryDnaModel dnaModel, double[] dnaModelParameterArray, AsyncCallback callback, ExecutionMode executionMode)
        {
            throw new System.NotImplementedException();
        }

        /// <summary>
        /// Ends an asynchronous evalutation
        /// </summary>
        public double EndEvaluation(IAsyncResult asyncResult)
        {
            throw new System.NotImplementedException();
        }

        /// <summary>
        /// Recursively traverses the tree and identifies all interior nodes
        /// </summary>
        private void ExploreNode(Node currentNode)
        {
            if (currentNode.ChildA != null && currentNode.ChildB != null)
            {
                _interiorNodes.Add(currentNode);
                ExploreNode(currentNode.ChildA);
                ExploreNode(currentNode.ChildB);
            }
        }
        /// <summary>
        /// Recursively enumerates all possible interior node configurations
        /// </summary>
        /// <param name="interiorIndex"></param>
        private void NestedLoop(int interiorIndex)
        {
            //for (int i = 0; i < _bases.Length; i++)
            //{
            //    _interiorNodes[interiorIndex].CurrentNode.SequenceCharacters = _bases[i];
            //    if (i == _interiorNodes.Count - 1)
            //        EvaluateConfiguration(_currentTree);
            //    else if(i < _interiorNodes)
            //        NestedLoop(i++);
            //}
        }

        /// <summary>
        /// Evaluates the configuration of the tree with all interior positions filled
        /// </summary>
        /// <param name="tree"></param>
        private void EvaluateConfiguration(PhylogeneticTree tree)
        {

        }
    }
}
